#ifndef __Encrypt_h__
#define __Encrypt_h__

#include "stdafx.h"

#define CC_HOST_IS_BIG_ENDIAN (bool)(*(unsigned short *)"\0\xff" < 0x100)
#define CC_SWAP32(i)  ((i & 0x000000ff) << 24 | (i & 0x0000ff00) << 8 | (i & 0x00ff0000) >> 8 | (i & 0xff000000) >> 24)
#define CC_SWAP16(i)  ((i & 0x00ff) << 8 | (i &0xff00) >> 8)
#define CC_SWAP_INT32_LITTLE_TO_HOST(i) ((CC_HOST_IS_BIG_ENDIAN == true)? CC_SWAP32(i) : (i) )
#define CC_SWAP_INT16_LITTLE_TO_HOST(i) ((CC_HOST_IS_BIG_ENDIAN == true)? CC_SWAP16(i) : (i) )
#define CC_SWAP_INT32_BIG_TO_HOST(i)    ((CC_HOST_IS_BIG_ENDIAN == true)? (i) : CC_SWAP32(i) )
#define CC_SWAP_INT16_BIG_TO_HOST(i)    ((CC_HOST_IS_BIG_ENDIAN == true)? (i):  CC_SWAP16(i) )

typedef long ssize_t;

extern const char CCZv_sig[4];
extern const char CCZp_sig[4];
extern unsigned int s_uEncryptedPvrKeyParts[4];

struct CCZHeader {
	unsigned char   sig[4];             /** Signature. Should be 'CCZv' 4 bytes. */
	unsigned short  compression_type;   /** Should be 0. */
	unsigned short  version;            /** Should be 2 (although version type==1 is also supported). */
	unsigned int    reserved;           /** Reserved for users. */
	unsigned int    len;                /** Size of the uncompressed file. */
};

void decodeEncodedPvr(unsigned int *data, ssize_t len);
bool isCCZVBuffer(unsigned char *buff, int buffLen);
bool isCCZPBuffer(unsigned char *buff, int buffLen);
int calcChecksumPvr(const unsigned int *data, ssize_t len);

#endif

